package ugc

import (
	"encoding/json"
	"sensitives/service/dic"
	"strconv"

	"github.com/gin-gonic/gin"
)

type ctmedia struct {
	common
}

// Ctmedia 公众号
var Ctmedia ctmedia

// Faq 公众号问答
func (filter *ctmedia) Faq(cx *gin.Context) {
	siteid, _ := strconv.Atoi(cx.Param("siteid"))
	question := cx.PostForm("question")
	type response struct {
		Code bool        `json:"code"`
		Data []sensitive `json:"data"`
	}
	filter.SensWords = make([]sensitive, 0)
	output := response{Code: false, Data: filter.SensWords}
	if question == "" {
		sensUser, _ := json.Marshal(output)
		cx.Writer.Write([]byte(sensUser))
	}
	userDic := dic.CloudMap[siteid].User
	filter.filter(question, "question", &userDic)
	output = response{Code: true, Data: filter.SensWords}
	sensUser, _ := json.Marshal(output)
	cx.Writer.Write(sensUser)
}
